package com.qu.waibao.baidu;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.baidu.mapapi.search.core.PoiInfo;
import com.qu.waibao.R;
import com.qu.waibao.base.BaseRecyclerAdapter;
import com.qu.waibao.nearby.ShopPerson;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @描述 describe
 * @作者 Administrator
 * @创建时间 2018/7/27 18:17
 * @邮箱 1123599561@qq.com
 */
public class DingweiAdapter extends BaseRecyclerAdapter<ShopPerson> {
    public DingweiAdapter(Context context, int mode) {
        super(context, mode);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        return new DingweiViewHolder(mInflater.inflate(R.layout.dingwei_recycler_item,parent,false));
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, ShopPerson item, int position) {
        DingweiViewHolder dingweiViewHolder = (DingweiViewHolder) holder;
        dingweiViewHolder.tv_title.setText(item.getName());
        dingweiViewHolder.tv_content.setText(item.getAddress_full());
        dingweiViewHolder.tv_service.setText(item.getBusiness_main());
        if(!TextUtils.isEmpty(item.getScore_avg())){
            dingweiViewHolder.tv_score.setText(item.getScore_avg()+"分");
        }else {
            dingweiViewHolder.tv_score.setText("0.0分");
        }
        if(item.getFlag() == 1){
            dingweiViewHolder.mRoot.setBackgroundResource(R.color.market_bg);
        }else {
            dingweiViewHolder.mRoot.setBackgroundResource(R.color.whites);
        }
        dingweiViewHolder.tv_danghang.setTag(position);
        dingweiViewHolder.tv_danghang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = (int) v.getTag();
                if(onItemDangClickListener != null){
                    onItemDangClickListener.onItemDangClick(position);
                }
            }
        });
    }

    class DingweiViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.tv_title)
        TextView tv_title;
        @BindView(R.id.tv_content)
        TextView tv_content;
        @BindView(R.id.tv_danghang)
        TextView tv_danghang;
        @BindView(R.id.tv_service)
        TextView tv_service;
        @BindView(R.id.tv_score)
        TextView tv_score;
        @BindView(R.id.mRoot)
        LinearLayout mRoot;
        public DingweiViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

    public interface OnItemDangClickListener{
        void onItemDangClick(int position);
    }
    private OnItemDangClickListener onItemDangClickListener;
    public void setOnItemDangClickListener(OnItemDangClickListener onItemDangClickListener){
        this.onItemDangClickListener = onItemDangClickListener;
    }
}
